package com.reger.test.l2cache;

import java.util.concurrent.TimeUnit;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.reger.l2cache.cache.annotation.L2Cache;
import com.reger.l2cache.cache.annotation.L2DelCache;
import com.reger.l2cache.cache.annotation.L2PutCache;

@Component
public class CacheTestImpl implements CacheTest {

	private static final Logger log = LoggerFactory.getLogger(CacheTestImpl.class);

	@Override
	@L2Cache(key = "'test.get.'+#id", timeOut = 2000)
	public String findById(int id) throws InterruptedException {
		log.info("进入缓存方法 id=" + id);
		System.err.println("==============>>>");
		TimeUnit.SECONDS.sleep(10);
		return "hello word ! findById " + id;
	}

	@Override
	@L2DelCache(key = "'test.get.'+#id")
	public void del(int id) {
		log.info("执行完毕会清理缓存...");
	}

	@Override
	@L2PutCache(key = "'test.get.'+#id", timeOut = 20000)
	public String updateById(int id) {
		log.info("执行完毕会更新缓存...");
		return "hello word ! updateById " + id;
	}
}
